#include <iostream>
using namespace std;

#include <misc/argvutils.h>
#include <dataspace/dataspace.h>

void print_usage(char* argv0)
{
  cerr << argv0 << " --ds-fn=<ds-fn> <axis>=[L][:[R]]" << endl;
  cerr << "E.g.:" << endl;
  cerr << "\t" << argv0 << " --ds-fn=a.DS ibes_ticker=IBM datetime=20080101-000000" << endl;
  exit(1);
}

int main(int argc, char** argv)
{
  try {
    DictVector<string, string> args = argv_utils::parse_to_dict(argc, argv);
    if (args.size() == 0 || args.has_key("--help") || args.has_key("-h")) {
      print_usage(argv[0]);
    }
    
    string ds_fn = args.get("--ds-fn");
    DataSpace ds;
    ds.load(ds_fn, false);

    args.remove("--ds-fn");
    vector<string> spec_axes;
    AxesRange r(&ds.axes);
    int ii = 2;
    DynObject ii_o(DynTypeManager::get()->get_dyntype("int"),
		   membuf_t((char*)&ii, sizeof ii));
    r.set_left("X", ii_o);
    r.set_right("X", ii_o);
    r.set_left("Y", ii_o);
    r.set_right("Y", ii_o);    
    r.dump();
    
    vector<pair<axis_index_t, axis_index_t> > axis_ranges;
    axis_ranges = ds.axes.get_axis_indexes_range(r);

    vector<AxesCoor> coors;
    vector<DynObject> values;
    ds.onedim_range(axis_ranges, &coors, &values);
    for (size_t i = 0; i < values.size(); i++) {
      cout << values[i] << " "; coors[i].print(cout); cout << endl;
    }

  } catch (Error& e) {
    cerr << "caught Error: " << e.msg() << endl;
  }
}
